import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    //全局存储数据的地方
    isLogin:localStorage.getItem("loginkey") ? true : false,
    userInfo:localStorage.getItem("loginkey"),
  },
  getters: {
  },
  mutations: {
    //同步更改 state 区域的地方
    login(state,paylode) {
      state.isLogin = true;
      state.userInfo = paylode.data;
      localStorage.setItem("loginkey",paylode.data);
    },
    logout(state) {
      state.isLogin = false;
      state.userInfo = {};
      localStorage.removeItem("loginkey");
    }
  },
  actions: {
    //异步更改 state 区域的地方
    asclogin(context,paylode) {
      context.commit("login",paylode);
    },
    asclogout(context) {
      context.commit("logout");
    }
    
  },
  modules: {
  }
})
